﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CI.Misc;
using NUnit.Framework;
using CI;
using CI.Interfaces;
using CI.Mesopotamia;
using CI.Organism;
using System.Reflection;

namespace Mesopotamia.UnitTests
{
    /// <summary>MSRB hosting environment Unit Testing</summary>
    [TestFixture]
    public class CollisionDetectionTests
    {
        readonly CI.Mesopotamia.CollisionDetection _collisionDetection = new CI.Mesopotamia.CollisionDetection();
        MethodInfo DetectCollisionsPairs;
        MethodInfo CalculateCollisionEnergyResult;
        IHostingEnvironment _hostingEnvironment = new CI.Mesopotamia.MSRBHost(new MockHostingEnvironmentPhysical(), new CI.Mesopotamia.ScenarioLocalXML());
        CollisionPairCollection _collisionPairCollection = new CollisionPairCollection();
        readonly OrganismCollection _organisms = new OrganismCollection();
        private SimEnv _simEnv = SimEnv.Instance;

        [SetUp]
        public void Setup()
        {
            // clear the previous list
            _organisms.Alive.Clear();
            _organisms.Dead.Clear();
            _organisms.Inactive.Clear();

            _hostingEnvironment = new CI.Mesopotamia.MSRBHost(new MockHostingEnvironmentPhysical(), new ScenarioLocalXML());
            _hostingEnvironment.Organisms = _organisms;

            DetectCollisionsPairs = _collisionDetection.GetType().GetMethod("DetectCollisionsPairs", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(DetectCollisionsPairs, "Unable to find private method DetectCollisionsPairs");

            CalculateCollisionEnergyResult = _collisionDetection.GetType().GetMethod("CalculateCollisionEnergyResult", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(CalculateCollisionEnergyResult, "Unable to find private method CalculateCollisionEnergyResult");


            // setup organisms
            // add a pair of organisms
            _organisms.AliveAdd(new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 0, 0));
            _organisms.AliveAdd(new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 0, 0));
            _organisms.AliveAdd(new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 0, 0));
            _organisms.AliveAdd(new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 0, 0));

            // give them all different CIET
            _organisms.Alive[0].CIET = 10;
            _organisms.Alive[1].CIET = 20;
            _organisms.Alive[2].CIET = 30;
            _organisms.Alive[3].CIET = 40;

            // make them all amoebas
            new Amoeba(_organisms.Alive[0], Guid.NewGuid());
            new Amoeba(_organisms.Alive[1], Guid.NewGuid());
            new Amoeba(_organisms.Alive[2], Guid.NewGuid());
            new Amoeba(_organisms.Alive[3], Guid.NewGuid());

            // set them all as being active
            _organisms.Alive[0].Cells[0].Active = true;
            _organisms.Alive[1].Cells[0].Active = true;
            _organisms.Alive[2].Cells[0].Active = true;
            _organisms.Alive[3].Cells[0].Active = true;
        }

        #region Collision Detection

        [Test, ExpectedException(typeof(TargetInvocationException))]
        public void DetectCollisionsNullOrganismsArgumentException()
        {
            // check for null organisms 

            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { null });
        }

        /// <summary>
        /// Pass in a empty list of organisms and you should not get a null list back
        /// </summary>
        [Test]
        public void DetectCollisionsPairsEmptyOrganismListReturnNotNull()
        {
            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            _collisionPairCollection = (CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { new CI.Organism.OrganismCollection() });
            Assert.IsNotNull(_collisionPairCollection, "Collection Pair is null");
        }

        /// <summary>
        /// Pass in a empty list of organisms and you should get a empty pair list back
        /// </summary>
        [Test]
        public void DetectCollisionsPairsEmptyOrganismListReturnListNotEmpty()
        {
            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            _collisionPairCollection = (CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { new CI.Organism.OrganismCollection() });
            Assert.IsEmpty(_collisionPairCollection, "Collision Pair list is not empty");
        }

        /// <summary>
        /// This test checks to make sure it misses
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXMissYMissZMissEmpty()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 2, 3));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(5, 3, 4));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(100, 2, 3));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(150, 2, 3));

            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            Assert.IsEmpty((CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms }), "Collision should have missed");
        }

        /// <summary>
        /// This test checks to make sure it misses
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYMissZMissEmpty()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 200, 300));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(1, 300, 100));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(100, 2, 3));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(150, 2, 3));

            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            Assert.IsEmpty((CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms }), "Collision should have missed");
        }

        /// <summary>
        /// This test checks to make sure it misses
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZMissEmpty()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 2, 300));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(1, 2, 400));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(100, 2, 3));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(150, 2, 3));

            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            Assert.IsEmpty((CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms }), "Collision should have missed");
        }

        /// <summary>
        /// This test checks to make sure it misses
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXMissYHitZHitEmpty()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(100, 2, 3));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(200, 2, 3));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(400, 2, 3));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(150, 2, 3));

            ((CI.Mesopotamia.MSRBHost)SimEnv.Instance.HostEnv).SystemHeartBeat += 10;
            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            Assert.IsEmpty((CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms }), "Collision should have missed");
        }

        /// <summary>
        /// This test checks to make sure it misses
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYMissZHitEmpty()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 200, 4));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(1, 300, 4));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(100, 2, 3));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(150, 2, 3));

            ((CI.Mesopotamia.MSRBHost)SimEnv.Instance.HostEnv).SystemHeartBeat += 11;
            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            Assert.IsEmpty((CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms }), "Collision should have missed");
        }

        /// <summary>
        /// This test checks to make sure it hits and its within Boundary X 
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZHitWithinBoundaryXNotEmpty()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 2, 3, 5, 5, 5));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(11, 2, 3, 5, 5, 5));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(100, 2, 3));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(150, 2, 3));

            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            Assert.IsNotEmpty((CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms }), "Collision should have NOT missed");
        }

        /// <summary>
        /// This test checks to make sure it hits and its within Boundary Y
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZHitWithinBoundaryYNotEmpty()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 2, 3, 5, 5, 5));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(1, 12, 3, 5, 5, 5));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(100, 2, 3));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(150, 2, 3));

            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            Assert.IsNotEmpty((CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms }), "Collision should have NOT missed");
        }

        /// <summary>
        /// This test checks to make sure it hits and its within Boundary Z
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZHitWithinBoundaryZNotEmpty()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 2, 3, 5, 5, 5));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(1, 2, 13, 5, 5, 5));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(100, 2, 3));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(150, 2, 3));

            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            Assert.IsNotEmpty((CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms }), "Collision should have NOT missed");
        }
        /// <summary>
        /// This test checks to make sure it hits and the correct collection pair is returned out of 2 organims put in
        /// Match 1 and 2 in collection
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZHitNotEmptyPair12()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 2, 3, 5, 5, 5));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(5, 2, 3, 5, 5, 5));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(100, 2, 3));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(150, 2, 3));

            // change system hb else dirty locations wont recalculate
            ((CI.Mesopotamia.MSRBHost)SimEnv.Instance.HostEnv).SystemHeartBeat += 2;

            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            _collisionPairCollection = (CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms });
            Assert.AreEqual(1, _collisionPairCollection.Count, "Should have 1 one match only");
            Assert.AreEqual(_organisms.Alive[0], _collisionPairCollection[0].Organism1, "Organism 1 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[1], _collisionPairCollection[0].Organism2, "Organism 2 not found in collection pair returned");

        }


        /// <summary>
        /// This test checks to make sure it hits and the correct collection pair is returned out of 2 organims put in
        /// Match 1 and 3 in collection
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZHitNotEmptyPair13()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 2, 3, 5, 5, 5));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(50, 2, 3));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(10, 2, 3, 5, 5, 5));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(150, 2, 3));

            // change system hb else dirty locations wont recalculate
            ((CI.Mesopotamia.MSRBHost)SimEnv.Instance.HostEnv).SystemHeartBeat += 3;

            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            _collisionPairCollection = (CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms });
            Assert.AreEqual(1, _collisionPairCollection.Count, "Should have 1 one match only");
            Assert.AreEqual(_organisms.Alive[0], _collisionPairCollection[0].Organism1, "Organism 1 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[2], _collisionPairCollection[0].Organism2, "Organism 3 not found in collection pair returned");
        }

        /// <summary>
        /// This test checks to make sure it hits and the correct collection pair is returned out of 2 organims put in
        /// Match 1 and 4 in collection
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZHitNotEmptyPair14()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 2, 3, 5, 5, 5));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(10, 2, 30));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(15, 2, 300));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(5, 2, 3, 5, 5, 5));

            // change system hb else dirty locations wont recalculate
            ((CI.Mesopotamia.MSRBHost)SimEnv.Instance.HostEnv).SystemHeartBeat += 4;

            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            _collisionPairCollection = (CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms });
            Assert.AreEqual(1, _collisionPairCollection.Count, "Should have 1 one match only");
            Assert.AreEqual(_organisms.Alive[0], _collisionPairCollection[0].Organism1, "Organism 1 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[3], _collisionPairCollection[0].Organism2, "Organism 4 not found in collection pair returned");
        }

        /// <summary>
        /// This test checks to make sure it hits and the correct collection pair is returned out of 2 organims put in
        /// Match 2 and 3 in collection
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZHitNotEmptyPair23()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 2, 30));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(5, 2, 3, 5, 5, 5));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(10, 2, 3, 5, 5, 5));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(15, 20, 3));

            // change system hb else dirty locations wont recalculate
            ((CI.Mesopotamia.MSRBHost)SimEnv.Instance.HostEnv).SystemHeartBeat += 5;

            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            _collisionPairCollection = (CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms });
            Assert.AreEqual(1, _collisionPairCollection.Count, "Should have 1 one match only");
            Assert.AreEqual(_organisms.Alive[1], _collisionPairCollection[0].Organism1, "Organism 2 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[2], _collisionPairCollection[0].Organism2, "Organism 3 not found in collection pair returned");
        }

        /// <summary>
        /// This test checks to make sure it hits and the correct collection pair is returned out of 2 organims put in
        /// Match 2 and 4 in collection
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZHitNotEmptyPair24()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 20, 3));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(5, 2, 3, 5, 5, 5));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(10, 2, 30));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(15, 2, 3, 5, 5, 5));

            // change system hb else dirty locations wont recalculate
            ((CI.Mesopotamia.MSRBHost)SimEnv.Instance.HostEnv).SystemHeartBeat += 6;
            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            _collisionPairCollection = (CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms });
            Assert.AreEqual(1, _collisionPairCollection.Count, "Should have 1 one match only");
            Assert.AreEqual(_organisms.Alive[1], _collisionPairCollection[0].Organism1, "Organism 2 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[3], _collisionPairCollection[0].Organism2, "Organism 4 not found in collection pair returned");
        }

        /// <summary>
        /// This test checks to make sure it hits and the correct collection pair is returned out of 2 organims put in
        /// Match 3 and 4 in collection
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZHitNotEmptyPair34()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 20, 3));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(5, 2, 30));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(10, 2, 3, 5, 5, 5));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(15, 2, 3, 5, 5, 5));

            // change system hb else dirty locations wont recalculate
            ((CI.Mesopotamia.MSRBHost)SimEnv.Instance.HostEnv).SystemHeartBeat += 7;
            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            _collisionPairCollection = (CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms });
            Assert.AreEqual(1, _collisionPairCollection.Count, "Should have 1 one match only");
            Assert.AreEqual(_organisms.Alive[2], _collisionPairCollection[0].Organism1, "Organism 3 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[3], _collisionPairCollection[0].Organism2, "Organism 4 not found in collection pair returned");
        }

        /// <summary>
        /// This test checks to make sure it hits and the correct collection pair is returned out of 2 organims put in
        /// Match 1 and 2 in collection and 3 and 4
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZHitNotEmptyPair1234()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 2, 3, 5, 5, 5));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(5, 2, 3, 5, 5, 5));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(10, 20, 3, 5, 5, 5));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(15, 25, 3, 5, 5, 5));

            // change system hb else dirty locations wont recalculate
            ((CI.Mesopotamia.MSRBHost)SimEnv.Instance.HostEnv).SystemHeartBeat += 8;
            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            _collisionPairCollection = (CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms });
            Assert.AreEqual(2, _collisionPairCollection.Count, "Should have 2 matches only");
            Assert.AreEqual(_organisms.Alive[0], _collisionPairCollection[0].Organism1, "Organism 1 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[1], _collisionPairCollection[0].Organism2, "Organism 2 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[2], _collisionPairCollection[1].Organism1, "Organism 1 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[3], _collisionPairCollection[1].Organism2, "Organism 2 not found in collection pair returned");

        }


        /// <summary>
        /// This test checks to make sure it hits and the correct collection pair is returned out of 2 organims put in
        /// Match 1 and 2 in collection and 1 and 4
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void DetectCollisionsXHitYHitZHitNotEmptyPair1214()
        {
            // set organisms location
            _organisms.Alive[0].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[0], new Location(1, 2, 3, 5, 5, 5));
            _organisms.Alive[1].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[1], new Location(5, 2, 3, 5, 5, 5));
            _organisms.Alive[2].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[2], new Location(100, 2, 3, 5, 5, 5));
            _organisms.Alive[3].HostingEnvironment.HostingEnvironmentPhysical.SetLocation(_organisms.Alive[3], new Location(-6, 2, 3, 5, 5, 5));

            // change system hb else dirty locations wont recalculate
            ((CI.Mesopotamia.MSRBHost)SimEnv.Instance.HostEnv).SystemHeartBeat += 9;
            // detect dirty locations
            _organisms.DirtyLocationsRebuild();

            _collisionPairCollection = (CollisionPairCollection)DetectCollisionsPairs.Invoke(_collisionDetection, new object[] { _organisms });
            Assert.AreEqual(2, _collisionPairCollection.Count, "Should have 2 matches only");
            Assert.AreEqual(_organisms.Alive[0], _collisionPairCollection[0].Organism1, "Organism 1 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[1], _collisionPairCollection[0].Organism2, "Organism 2 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[0], _collisionPairCollection[1].Organism1, "Organism 1 not found in collection pair returned");
            Assert.AreEqual(_organisms.Alive[3], _collisionPairCollection[1].Organism2, "Organism 4 not found in collection pair returned");

        }
        #endregion

        #region Energy collision results

        /// <summary>
        /// Check to make sure a null collection is getting picked up
        /// </summary>
        [Test, ExpectedException(typeof(TargetInvocationException))]
        public void CalculateCollisionEnergyResultNullCollectionException()
        {
            CalculateCollisionEnergyResult.Invoke(_collisionDetection, new object[] { null });
        }

        /// <summary>
        /// compare org 1 and 2 and 1 is going to be getting 2's energy
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void CalculateCollisionEnergyResultOrg1WinsOrg2EnergyAreEqual()
        {
            _collisionPairCollection.Add(new CollisionPair(_organisms.Alive[0], _organisms.Alive[1]));
            _organisms.Alive[0].CIET = 20;
            _organisms.Alive[0].Energy = 100;
            _organisms.Alive[1].CIET = 10;
            _organisms.Alive[1].Energy = 200;

            CalculateCollisionEnergyResult.Invoke(_collisionDetection, new object[] { _collisionPairCollection });

            Assert.AreEqual(120, _organisms.Alive[0].Energy, "Org 1 should have gained Org 2 energy");
            Assert.AreEqual(180, _organisms.Alive[1].Energy, "Org 2 should have lost energy to Org1");

        }

        /// <summary>
        /// compare org 1 and 2 and 2 is going to be getting 1's energy
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void CalculateCollisionEnergyResultOrg2WinsOrg1EnergyAreEqual()
        {
            _collisionPairCollection.Add(new CollisionPair(_organisms.Alive[0], _organisms.Alive[1]));
            _organisms.Alive[1].CIET = 20;
            _organisms.Alive[1].Energy = 100;
            _organisms.Alive[0].CIET = 10;
            _organisms.Alive[0].Energy = 200;

            CalculateCollisionEnergyResult.Invoke(_collisionDetection, new object[] { _collisionPairCollection });

            Assert.AreEqual(120, _organisms.Alive[1].Energy, "Org 2 should have gained Org 1 energy");
            Assert.AreEqual(180, _organisms.Alive[0].Energy, "Org 1 should have lost energy to Org2");
        }

        /// <summary>
        /// compare org 1 and 2 and both are equal
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void CalculateCollisionEnergyResultSameCIETNoWinnerAreEqual()
        {
            _collisionPairCollection.Add(new CollisionPair(_organisms.Alive[0], _organisms.Alive[1]));
            _organisms.Alive[1].CIET = 20;
            _organisms.Alive[1].Energy = 100;
            _organisms.Alive[0].CIET = 20;
            _organisms.Alive[0].Energy = 200;

            CalculateCollisionEnergyResult.Invoke(_collisionDetection, new object[] { _collisionPairCollection });

            Assert.AreEqual(100, _organisms.Alive[1].Energy, "energy should have stayed the same");
            Assert.AreEqual(200, _organisms.Alive[0].Energy, "energy should have stayed the same");
        }

        /// <summary>
        /// check to make sure that a live Organism hitting a dead Organism will take some of its body mass energy
        /// e.g. its body fat.... once that has depleted it is removed from all dead list and screen
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void CalculateCollisionEnergyDeadOrganismTrue()
        {
            _collisionPairCollection.Add(new CollisionPair(_organisms.Alive[0], _organisms.Alive[1]));
            _organisms.Alive[0].CIET = 20;
            _organisms.Alive[0].Energy = 30;
            _organisms.Alive[0].BMEnergy = 100;
            _organisms.Alive[1].CIET = 50;
            _organisms.Alive[1].Energy = 200;

            CalculateCollisionEnergyResult.Invoke(_collisionDetection, new object[] { _collisionPairCollection });

            Assert.AreEqual(0, _organisms.Dead[0].Energy, "Org energy should be 0");
            Assert.AreEqual(80, _organisms.Dead[0].BMEnergy, "Org bme should be dereased");
            Assert.AreEqual(250, _organisms.Alive[0].Energy, "energy should have stayed the same");

        }

        /// <summary>
        /// make sure once an orgaisms body mass energy is depleted it is removed from all dead list and screen        /// 
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void CalculateCollisionEnergyDeadRemoveFalse()
        {
            IOrganism _testOrg = _organisms.Alive[0];

            _collisionPairCollection.Add(new CollisionPair(_organisms.Alive[0], _organisms.Alive[1]));
            _organisms.Alive[0].CIET = 20;
            _organisms.Alive[0].Energy = 20;
            _organisms.Alive[0].BMEnergy = 20;
            _organisms.Alive[1].CIET = 50;
            _organisms.Alive[1].Energy = 200;

            CalculateCollisionEnergyResult.Invoke(_collisionDetection, new object[] { _collisionPairCollection });
            Assert.IsFalse(_organisms.Alive.Contains(_testOrg), "Org should be removed from alive list");
            Assert.IsFalse(_organisms.Dead.Contains(_testOrg), "Org should be removed from dead list");
        }

        /// <summary>
        /// make sure once an orgaisms body mass energy is depleted its active state is changed
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void CalculateCollisionEnergyDeadActiveStateTrue()
        {
            IOrganism _testOrg = _organisms.Alive[0];

            _collisionPairCollection.Add(new CollisionPair(_organisms.Alive[0], _organisms.Alive[1]));
            _organisms.Alive[0].CIET = 20;
            _organisms.Alive[0].Energy = 20;
            _organisms.Alive[0].BMEnergy = 20;
            _organisms.Alive[1].CIET = 50;
            _organisms.Alive[1].Energy = 200;

            CalculateCollisionEnergyResult.Invoke(_collisionDetection, new object[] { _collisionPairCollection });

            Assert.AreEqual(ActiveState.Ignore, _testOrg.ActiveState, "Active state should be set to ignore");
        }

        /// <summary>
        /// make sure once an orgaisms body mass energy is depleted its moved into the inactive list
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void CalculateCollisionEnergyDeadInactiveListTrue()
        {
            IOrganism _testOrg = _organisms.Alive[0];

            _collisionPairCollection.Add(new CollisionPair(_organisms.Alive[0], _organisms.Alive[1]));
            _organisms.Alive[0].CIET = 20;
            _organisms.Alive[0].Energy = 20;
            _organisms.Alive[0].BMEnergy = 20;
            _organisms.Alive[1].CIET = 50;
            _organisms.Alive[1].Energy = 200;

            CalculateCollisionEnergyResult.Invoke(_collisionDetection, new object[] { _collisionPairCollection });
            Assert.IsTrue(_organisms.Inactive.Contains(_testOrg), "Org should be in inactive list");
        }


        #endregion

        #region Proccess Collisions

        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "Organisms")]
        public void ProccessCollisionsNullCollectionException()
        {
            _collisionDetection.UpdateOrganisms(null);
        }

        #endregion

        #region Fittest Sorting

        /// <summary>
        /// Call the fittest ordered list and with a null parameter
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "organisms")]
        public void FittestNullCollectionException()
        {
            _collisionDetection.Fittest(null);
        }

        /// <summary>
        /// Call the fittest ordered list with 6 values and make sure the collection comes back has 6 items
        /// </summary>
        [Test]
        public void FittestCollectionInOutCountEqual()
        {
            // organisms
            IOrganismCollection _organisms = new CI.Organism.OrganismCollection();

            // add 3 alive
            _organisms.AliveAdd(new CI.Organism.Organism(_hostingEnvironment));
            _organisms.AliveAdd(new CI.Organism.Organism(_hostingEnvironment));
            _organisms.AliveAdd(new CI.Organism.Organism(_hostingEnvironment));

            // add 2 dead
            _organisms.DeadAdd(new CI.Organism.Organism(_hostingEnvironment));
            _organisms.DeadAdd(new CI.Organism.Organism(_hostingEnvironment));

            // add 1 inactive
            _organisms.InactiveAdd(new CI.Organism.Organism(_hostingEnvironment));

            // get the result
            List<IOrganism> _results = _collisionDetection.Fittest(_organisms);

            // make sure it has 6 items
            Assert.AreEqual(6, _results.Count, "Expected 6 items in the list");
        }

        /// <summary>
        /// Call the fittest ordered list with 3 values and make sure they come out sorted with children
        /// </summary>
        [Test]
        public void FittestSortedChildrenSorted()
        {
            // organisms
            IOrganismCollection _organisms = new CI.Organism.OrganismCollection();

            // add 3 alive
            _organisms.AliveAdd(new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0));
            _organisms.Alive[0].Energy = 600;
            _organisms.Alive[0].Organisms = _organisms;
            _organisms.Alive[0].NeuralSystem = new SimpleNeuralSystem(_organisms.Alive[0]);
            _organisms.Alive[0].Cells.Add(new CI.Organism.Amoeba(_organisms.Alive[0], Guid.NewGuid()));
            _organisms.Alive[0].Cells[0].Active = true;
            _organisms.AliveAdd(new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0));
            _organisms.Alive[1].Energy = 500;
            _organisms.Alive[1].Organisms = _organisms;
            _organisms.Alive[1].NeuralSystem = new SimpleNeuralSystem(_organisms.Alive[1]);
            _organisms.Alive[1].Cells.Add(new CI.Organism.Amoeba(_organisms.Alive[1], Guid.NewGuid()));
            _organisms.Alive[1].Cells[0].Active = true;
            _organisms.AliveAdd(new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0));
            _organisms.Alive[2].Energy = 400;
            _organisms.Alive[2].Organisms = _organisms;
            _organisms.Alive[2].NeuralSystem = new SimpleNeuralSystem(_organisms.Alive[2]);
            _organisms.Alive[2].Cells.Add(new CI.Organism.Amoeba(_organisms.Alive[2], Guid.NewGuid()));
            _organisms.Alive[2].Cells[0].Active = true;

            // add 2 dead
            _organisms.DeadAdd(new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0));
            _organisms.Dead[0].Energy = 300;
            _organisms.Dead[0].Organisms = _organisms;
            _organisms.Dead[0].NeuralSystem = new SimpleNeuralSystem(_organisms.Dead[0]);
            _organisms.Dead[0].Cells.Add(new Amoeba(_organisms.Dead[0], Guid.NewGuid()));
            _organisms.Dead[0].Cells[0].Active = true;
            _organisms.DeadAdd(new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0));
            _organisms.Dead[1].Energy = 200;
            _organisms.Dead[1].Organisms = _organisms;
            _organisms.Dead[1].NeuralSystem = new SimpleNeuralSystem(_organisms.Dead[1]);
            _organisms.Dead[1].Cells.Add(new Amoeba(_organisms.Dead[1], Guid.NewGuid()));
            _organisms.Dead[1].Cells[0].Active = true;

            // add 1 inactive
            _organisms.InactiveAdd(new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0));
            _organisms.Inactive[0].Energy = 500;
            _organisms.Inactive[0].Organisms = _organisms;
            _organisms.Inactive[0].NeuralSystem = new SimpleNeuralSystem(_organisms.Inactive[0]);
            _organisms.Inactive[0].Cells.Add(new Amoeba(_organisms.Inactive[0], Guid.NewGuid()));
            _organisms.Inactive[0].Cells[0].Active = true;

            // create 2 children
            _organisms.Alive[0].ParentOrganisms.Add(_organisms.Inactive[0]);
            _organisms.Dead[0].ParentOrganisms.Add(_organisms.Inactive[0]);

            // get the result
            List<IOrganism> _results = _collisionDetection.Fittest(_organisms);

            // make the first one is the one with children
            Assert.AreEqual(_results[0], _organisms.Inactive[0], "Not sorted properly");

        }

        /// <summary>
        /// Call the fittest ordered list and with a null parameter
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "organisms")]
        public void EvaluateFitness_NullOrganism_Exception()
        {
            _collisionDetection.Fittest(null);
        }

        /// <summary>
        /// Evalute the fitness of the organism, if it has not children it should be zero
        /// </summary>
        [Test]
        public void EvaluateFitness_NoChildren_ZeroFitness()
        {
            long _testValue = 400;

            // create the organism
            IOrganism _organism = new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0);

            // give it a neural system
            new SimpleNeuralSystem(_organism);

            // set the energy
            _organism.Energy = _testValue;

            // check the result
            Assert.AreEqual(0, (long)_collisionDetection.EvaluateFitnessAndUpdateInternalFitnessValue(_organism));
            // check it saved it to the fitness value
            Assert.AreEqual(0, _organism.FitnessValue);
        }

        /// <summary>
        /// Evalute the fitness of the organism and consider its children
        /// </summary>
        [Test]
        public void EvaluateFitness_WithChildren_Equal()
        {
            long _testValue = 400;
            long _initEnergy = 100;

            // create the organism
            IOrganism _organism = new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0);
            _organism.Organisms.AliveAdd(_organism);
            // give it a neural system
            new SimpleNeuralSystem(_organism);

            // create 2 children
            IOrganism _organismChild1 = new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), _initEnergy, 0);
            IOrganism _organismChild2 = new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), _initEnergy, 0);
            _organismChild1.ParentOrganisms.Add(_organism);
            _organismChild2.ParentOrganisms.Add(_organism);

            // add them all to the same organism colleciton in the environment
            _organismChild1.Organisms.AliveAdd(_organismChild1);
            _organismChild2.Organisms.DeadAdd(_organismChild2);

            // set the energy
            _organism.Energy = _testValue;

            // check the result, start value plus the 2 children
            Assert.AreEqual(_testValue + _initEnergy * 2 - _organism.InitEnergy, (long)_collisionDetection.EvaluateFitnessAndUpdateInternalFitnessValue(_organism));
            // check it saved it to the fitness value
            Assert.AreEqual(_testValue + _initEnergy * 2 - _organism.InitEnergy, _organism.FitnessValue);
        }

        #endregion

        /// <summary>
        /// run the boundry clipping with no collection passed
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "organisms")]
        public void BoundryClippingNullIOrganismCollectionException()
        {
            _collisionDetection.BoundryClipping(null);
        }

        /// <summary>
        /// Send in one organism with a valid x and make sure it doesnt get clipped
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void BoundryClippingXValid()
        {
            _hostingEnvironment.Organisms.Alive.Clear();
            // create the organism and environment
            IOrganism _organism = new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0);
            _organism.Organisms.AliveAdd(_organism);
            _organism.Location.XAxis = 1;
            _organism.Location.YAxis = 1;
            _organism.Location.ZAxis = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryXRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryYRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryZRadiusMax = 1;


            // run the boundry checking
            _collisionDetection.BoundryClipping(new List<IOrganism>(_organism.Organisms));

            // make sure its still their
            Assert.AreEqual(1, _organism.Organisms.Alive.Count, "Expected Only one organism");

        }

        /// <summary>
        /// Send in one organism with a invalid x and make sure it does get clipped
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void BoundryClippingXInValid()
        {
            _hostingEnvironment.Organisms.Alive.Clear();
            // create the organism and environment
            IOrganism _organism = new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0);
            _organism.Organisms.AliveAdd(_organism);
            _organism.Location.XAxis = 1.1f;
            _organism.Location.YAxis = 1;
            _organism.Location.ZAxis = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryXRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryYRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryZRadiusMax = 1;

            // run the boundry checking
            _collisionDetection.BoundryClipping(new List<IOrganism>(_organism.Organisms));

            // make sure its not their
            Assert.AreEqual(0, _organism.Organisms.Alive.Count, "Expected no organisms");

        }

        /// <summary>
        /// Send in one organism with a valid Y and make sure it doesnt get clipped
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void BoundryClippingYValid()
        {
            _hostingEnvironment.Organisms.Alive.Clear();
            // create the organism and environment
            IOrganism _organism = new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0);
            _organism.Organisms.AliveAdd(_organism);
            _organism.Location.YAxis = 1;
            _organism.Location.YAxis = 1;
            _organism.Location.ZAxis = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryXRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryYRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryZRadiusMax = 1;

            // run the boundry checking
            _collisionDetection.BoundryClipping(new List<IOrganism>(_organism.Organisms));

            // make sure its still their
            Assert.AreEqual(1, _organism.Organisms.Alive.Count, "Expected Only one organism");

        }

        /// <summary>
        /// Send in one organism with a invalid Y and make sure it does get clipped
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void BoundryClippingYInValid()
        {
            _hostingEnvironment.Organisms.Alive.Clear();
            // create the organism and environment
            IOrganism _organism = new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0);
            _organism.Organisms.AliveAdd(_organism);
            _organism.Location.YAxis = 1.1f;
            _organism.Location.XAxis = 1;
            _organism.Location.ZAxis = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryXRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryYRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryZRadiusMax = 1;

            // run the boundry checking
            _collisionDetection.BoundryClipping(new List<IOrganism>(_organism.Organisms));

            // make sure its not their
            Assert.AreEqual(0, _organism.Organisms.Alive.Count, "Expected no organisms");

        }

        /// <summary>
        /// Send in one organism with a valid z and make sure it doesnt get clipped
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void BoundryClippingZValid()
        {
            _hostingEnvironment.Organisms.Alive.Clear();
            // create the organism and environment
            IOrganism _organism = new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0);
            _organism.Organisms.AliveAdd(_organism);
            _organism.Location.XAxis = 1;
            _organism.Location.YAxis = 1;
            _organism.Location.ZAxis = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryXRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryYRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryZRadiusMax = 1;

            // run the boundry checking
            _collisionDetection.BoundryClipping(new List<IOrganism>(_organism.Organisms));

            // make sure its still their
            Assert.AreEqual(1, _organism.Organisms.Alive.Count, "Expected Only one organism");

        }

        /// <summary>
        /// Send in one organism with a invalid z and make sure it does get clipped
        /// </summary>
        [Test, Category("MultiThreaded")]
        public void BoundryClippingZInValid()
        {
            _hostingEnvironment.Organisms.Alive.Clear();
            // create the organism and environment
            IOrganism _organism = new CI.Organism.Organism(_hostingEnvironment, Guid.NewGuid(), 100, 0);
            _organism.Organisms.AliveAdd(_organism);
            _organism.Location.ZAxis = 1.1f;
            _organism.Location.XAxis = 1;
            _organism.Location.YAxis = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryXRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryYRadiusMax = 1;
            _organism.HostingEnvironment.EnvironmentScenario.BoundryZRadiusMax = 1;

            // run the boundry checking
            _collisionDetection.BoundryClipping(new List<IOrganism>(_organism.Organisms));

            // make sure its not their
            Assert.AreEqual(0, _organism.Organisms.Alive.Count, "Expected no organisms");

        }
    }
}
